package com.jike.noobmoney.mvp.view.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.adapter.ChannelsAdapter;
import com.jike.noobmoney.entity.MyTaskChannelEntity;
import com.jike.noobmoney.mvp.view.fragment.MyTaskFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Create by xuke on 2018/11/10
 * 我的任务
 */
public class MyTaskActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.channelTab)
    TabLayout channelTab;
    @BindView(R.id.viewpger)
    ViewPager viewpger;
    private List<MyTaskChannelEntity> tabNameList = new ArrayList<>();
    private List<Fragment> newsFragmentList = new ArrayList<>();

    @Override
    protected int layoutResID() {
        return R.layout.activity_my_get_task;
    }
    /**
     * 如果要全屏,重写这个方法返回false
     */
    public Boolean isfits() {
        return true;
    }

    /**
     * 如果要白色主题,重写这个方法返回false
     */
    public boolean ismain() {
        return true;
    }
    @Override
    protected void initData() {
        tvTitle.setText("我接的悬赏");
        tabNameList.add(new MyTaskChannelEntity("待完成", "1"));
        tabNameList.add(new MyTaskChannelEntity("审核中", "3"));
        tabNameList.add(new MyTaskChannelEntity("已审核", "4"));
        tabNameList.add(new MyTaskChannelEntity("审核失败", "2"));
        tabNameList.add(new MyTaskChannelEntity("被投诉", "5"));

        for (int i = 0; i < tabNameList.size(); i++) {
            MyTaskFragment newsListFragment = new MyTaskFragment();
            Bundle bundle = new Bundle();
            bundle.putString(MyTaskFragment.Channels, tabNameList.get(i).getStatus());
            newsListFragment.setArguments(bundle);
            newsFragmentList.add(newsListFragment);
            channelTab.addTab(channelTab.newTab().setText(tabNameList.get(i).getTitle()));
        }

        ChannelsAdapter adapter = new ChannelsAdapter(getSupportFragmentManager(), tabNameList, newsFragmentList);
        viewpger.setAdapter(adapter);
        channelTab.setupWithViewPager(viewpger);
        viewpger.setOffscreenPageLimit(3);
    }


    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
